<template>
  <el-container direction="vertical">
    <h3>该文件不支持在线查看，请手动下载</h3>
    <el-button style="width: 120px" type="primary" @click="download">下载</el-button>
  </el-container>
</template>

<script>
  export default {
    name: 'DownloadView',
    props: {
      id: {
        type: String,
        default: '1237025239384870914'
      },
      version: Number,
      applyId: String,
    },
    methods: {
      download() {
        this.$api.getFileBlob(this.id, this.version, this.applyId).then(res => {
          let filename = (()=>{
            return res.headers['content-disposition'].split(";")[1].split("=")[1];
          })()
          const url = window.URL.createObjectURL(new Blob([res.data]));
          const link = document.createElement('a');
          link.href = url;
          link.setAttribute('download', filename);
          document.body.appendChild(link);
          link.click();
        })
      }
    }
  }
</script>

<style scoped>

</style>
